<?php
class Application_Model_CartItem extends Application_Model_DomainObject{
	
	protected $_id;

	protected $_dateCreated;
	
	protected $_price;
	
	protected $_productName;
	
	protected $_quantity;
	
	protected $_productId;
	
	protected $_cartId;
	
	protected $_comment;
    
    protected $_image;
    
    protected $_url;

    private $_product;
	
	protected $_shipFee;
    
    protected $_shopId;
    
    protected $_isSelected;

    protected $_skuNo;

    private $_shop;

    public function getSubTotal(){
        return $this->_price * $this->_quantity;
    }

        /**
     * 返回对应的产品
     * @return Application_Model_Product 
     */
    public function getProduct(){
		if (null == $this->_product){
			$this->_product = new Application_Model_Product($this->ProductId);
		}
		return $this->_product;
	}
    
    /**
     * 返回产品的属性集合，如颜色，大小等
     * @return array 
     */
    public function getProps(){
        return array();
    }

        /**
     * 返回商品对应的店家
     * @return Application_Model_Shop 
     */
    public function getShop(){
        if(NULL == $this->_shop){
            $this->_shop = new Application_Model_Shop($this->_shopId);
        }
        return $this->_shop;
    }

        /**
	 * 返回数据库操作对象
	 * @return Application_Model_DbTable_CartItem
	 */
	private static function getDb(){
		return new Application_Model_DbTable_CartItem();
	}
	
	/**
	 * 根据cartId返回购物车项
	 * @param $cartId
	 * @return array
	 */
	public static function getByCartId($cartId,$isSeleted=FALSE){
		$db = Application_Model_CartItem::getDb();
		return $db->getByCartId($cartId,$isSeleted);
	}
	
	/**
	 * 根据购物车ID清空购物车
	 * @param $cartId
	 */
	public static function clearCart($cartId){
		return Application_Model_CartItem::getDb()->del(array('cartId'=>$cartId,'isSelected'=>1));	
	}
	
        
    protected $_sku;
    public function getSku(){
        if($this->_sku==NULL && $this->_skuNo!=null && $this->_skuNo!='')
            $this->_sku = Application_Model_Sku::getBySkuNo($this->_skuNo);
        return $this->_sku;
    }
}